package org.mil.util;

public class MyMath {
	/**
	 * 既约分数
	 * p_reduced:q_reduced=p:q
	 */
	public static int p_reduced(int p,int q){
		
		return p/gcd(p,q);
		
	}
	public static int q_reduced(int p,int q){
		return q/gcd(p,q);
		
	}
	public static String reducedRatio(int p,int q){
		return p_reduced(p,q)+":"+q_reduced(p,q);
	}
	/**
	 * 最大公约数
	 */
	public static int gcd(int p,int q){
		int r;
		while(p!=0 && q!=0){
			r=p%q;
			p=q;
			q=r;
		}
		return p+q;
		
	}
	
	public static void main(String[] arg) {
		System.out.println(gcd(21,6));
		System.out.println(reducedRatio(624000,336000));
	}
}
